import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class Leetcode155 {

    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(-2);
        minStack.push(0);
        minStack.push(-3);
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.top());
        System.out.println(minStack.getMin());
    }

    static class MinStack {
        int k[] = new int[99999999];
        int currentTopIndex = 0;
        int currentMin = Integer.MAX_VALUE;
        int currentMinIndex = -1;

        public MinStack() {

        }

        public void push(int val) {
            k[currentTopIndex] = val;
            if (currentMin > val) {
                currentMin = val;
                currentMinIndex = currentTopIndex;
            }

            currentTopIndex++;
        }

        public void pop() {
            if (currentMinIndex == currentTopIndex - 1) {
                currentMin = Integer.MAX_VALUE;
                for (int i = 0; i < currentTopIndex - 1; i++) {
                    if (k[i] < currentMin) {
                        currentMin = k[i];
                        currentMinIndex = i;
                    }
                }
            }

            currentTopIndex--;
        }

        public int top() {
            return k[currentTopIndex - 1];
        }

        public int getMin() {
            return currentMin;
        }
    }
}
